package it.polimi.traveldream.entities;

import it.polimi.traveldream.Group;
import it.polimi.traveldream.MD5Util;
import it.polimi.traveldream.UtenteDTO;

import java.io.Serializable;

import javax.persistence.*;

import com.sun.mail.smtp.DigestMD5;

import java.util.Calendar;
import java.util.Date;
import java.util.List;


/**
 * The persistent class for the user database table.
 * 
 */
@Entity
@NamedQuery(name="User.findAll", query="SELECT u FROM User u")
public class User implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private String email;
		
	private String cognome;

	@Temporal(TemporalType.TIMESTAMP)
	private Date dataregistrazione;
	
	private String nome;

	private String password;

	@ElementCollection(targetClass = Group.class)
    @CollectionTable(name = "user_group",joinColumns = @JoinColumn(name = "email"))
    @Enumerated(EnumType.STRING)
    @Column(name="groupname")
	private List<Group> groups;

	public User() {
	}

	public User(UtenteDTO client) {
		this.email        = client.getEmail();
        this.nome         = client.getNome();
        this.cognome      = client.getCognome();        
        this.password     = MD5Util.encrypt(client.getPassword());
        this.dataregistrazione = new Date();
           }

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getCognome() {
		return this.cognome;
	}

	public void setCognome(String cognome) {
		this.cognome = cognome;
	}

	public Date getDataregistrazione() {
		return this.dataregistrazione;
	}

	public void setDataregistrazione(Date dataregistrazione) {
		this.dataregistrazione = dataregistrazione;
	}

	public String getNome() {
		return this.nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public List<Group> getGroups() {
		return groups;
	}

	public void setGroups(List<Group> groups) {
		this.groups = groups;
	}

}